﻿@model Backend.JYD.Model.Cust.CustMarketingInfo
@using Backend.JYD.Common;
@using Backend.JYD.Business;
@using Backend.JYD.Web.Common;
@using Backend.JYD.Model.Cust;
@using Backend.JYD.Model.Task;
@{
    ViewBag.Title = "创建营销任务";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";
}
@using (Ajax.BeginForm("create", new AjaxOptions() { OnSuccess = "aftersave" }))
{
    @Html.ValidationSummary(true)
    <div class="ui_pop_body" style="width: 600px; height: 450px;">
        <div>
            <ul class="edit-ul">
                @{
            var taskId = NumberHelper.ObjectToInt64(this.ViewBag.TaskId);
            var detailId = NumberHelper.ObjectToInt64(this.ViewBag.TaskDetailId);
            var taskInfo = this.ViewBag.TaskInfo as TaskBaseInfo;
            if (taskId > 0 && detailId > 0 && taskInfo != null)
            {
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.TaskId)：</span>
                    <span class="s02"><label>@taskId</label><input type="hidden" value="@taskId" name="TaskId"/></span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.TaskId)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.TaskDetailId)：</span>
                    <span class="s02"><label>@detailId</label><input type="hidden" value="@detailId" name="TaskDetailId"/></span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.TaskDetailId)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustNo)：</span>
                   <span class="s02">@Html.DisplayTextFor(model => model.CustNo)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.CustNo)</i>
                </li>
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustName)：</span>
                    <span class="s02">@Html.DisplayTextFor(model => model.CustName)
                        @Html.HiddenFor(model => model.CustName)
                    </span>
                </li>
                }
                else
                {
                <li class="li01" id="liCustNo" style="display:none;">
                    <span class="s01">@Html.LabelFor(model => model.CustNo)：</span>
                    <span class="s02">
                        <input type="text" readonly="readonly" onfocus="this.blur();"  id="CustNo" name="CustNo"  data-val="true" data-val-required="客户号 字段是必需的。" />
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.CustNo)</i>
                </li>
                    @Html.HiddenFor(model => model.TaskDetailId)
                    @Html.HiddenFor(model => model.TaskId)
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.CustName)：</span>
                    <span class="s02">@Html.TextBoxFor(model => model.CustName)
                        <input type="button" value="选" style="width:20px;padding-left:10px;" onclick="openCust()"/>
                        <input type="button" value="清除" id="btnclear" style="width:40px;display:none; padding-left:10px;" onclick="clearCust()"/>
                    </span>
                </li>
                <li class="li01" id="liPaperType">
                    <span class="s01">@Html.LabelFor(model => model.PaperType) : </span>
                    <span class="s02">@Html.DropDownListFor(model => model.PaperType, JydHtmlHelper.ConvertItemFormCodeInfo(true, CodeManager.PaperType, Model == null ? string.Empty : Model.PaperType), new { id = "PaperType", style = "width:120px;" })</span>
                </li>
                 <li class="li01" id="liPaperNo">
                    <span class="s01">@Html.LabelFor(model => model.PaperNo) : </span>
                    <span class="s02">
                        @Html.TextBoxFor(model => model.PaperNo, new { id = "PaperNo" })
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.PaperNo)</i>
                </li>
                <li class="li01" id="liPhone">
                    <span class="s01">@Html.LabelFor(model => model.Phone)   : </span>
                    <span class="s02">@Html.TextBoxFor(model => model.Phone, new { id = "Phone" })
                         <label for="ephone" style="display:none;"><input type="checkbox" value="1" id="ephone" name="ephone" onclick="editPhone()"/>修改客户电话</label>
                    </span>
                </li>
                }
                }
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ScheduleTime)：</span>
                    <span class="s02">
                        <input  type="text" name="ScheduleTime" id="ScheduleTime" value="@(Model == null || !Model.ScheduleTime.HasValue ? string.Empty : DateTimeHelper.GetDateShortFormat(Model.ScheduleTime.Value))"  onfocus="WdatePicker()" readonly="readonly" class="text-box single-line" data-val="true" data-val-required="计划接触时间 字段是必需的。" />
                        <img class="hand" onclick="WdatePicker({el:'ScheduleTime'})" src="/skin/datepicker/skin/datePicker.gif" width="16" height="22" align="absmiddle" />
                    </span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.ScheduleTime)</i>
                </li>                
                <li class="li01">
                    <span class="s01">@Html.LabelFor(model => model.ValidDays)：</span>
                    <span class="s02">@Html.EditorFor(model => model.ValidDays)</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.ValidDays)</i>
                </li>
                <li class="li01"  style="height:80px;">
                    <span class="s01">@Html.LabelFor(model => model.Memo)：</span>
                    <span class="s02">@Html.TextAreaFor(model => model.Memo, new { @rows = "5", style="width:300px;" })</span>
                    <i class="i01">@Html.ValidationMessageFor(model => model.Memo)</i>
                </li>
                <li class="li01">
                    <span class="s01"></span>
                    <span class="s02">
                        <input type="submit" value="提交" onclick="return check()"/>
                        <input type="button" value="取消" onclick="closeWin()"/>
                    </span>
                </li>
            </ul>
        </div>
     </div>
    <script src="@Url.Content("~/skin/js/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
    <script src="/skin/datepicker/WdatePicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        function aftersave(data) {
            if (data.code) {
                closeWinAndReload();
            }
            else {
                alert(data.msg);
            }
        }

        function check() {
            if (!$('#CustName').val()) {
                alert("选择/填写执行客户。");
                return false;
            }
            var sdate = $('#ScheduleTime').val();
            if (!sdate) {
                alert("请选择计划接触时间。");
                return false;
            }
            else {
                if (!DateCompare("@DateTimeHelper.GetDateLongFormat(DateTime.Today)", sdate)) {
                    alert("计划接触时间，不能小于当前时间。");
                    return false;
                }
            }
            if (!$('#ValidDays').val()) {
                alert("请填写有效天数");
                return false;
            }

            return true;
        }

        function openCust() {
            //?type=real
            windowShowModalDialog("/cust/frame", window, 950, 720);
        }
        function editPhone() {
            if ($('#ephone').attr('checked') == "checked") {
                $("#Phone").removeAttr("readOnly");
            }
            else {
                $("#Phone").attr("readOnly", "readOnly");
            }
        }
        function clearCust() {
            $("#CustNo").val('');
            $("#liCustNo").hide();
            $("#liPaperType").show();
            $("#liPaperNo").show();
            $("#CustName").val('');
            $("#PaperType").val('');
            $("#PaperNo").val('');
            $("#Phone").val('');

            $('#btnPaper').show();
            $('#btnclear').hide();
            $('#ephone').parent().hide();
            $("#CustName").removeAttr("readOnly");
            $("#Phone").removeAttr("readOnly");
        }

        function returnChoose(no, name, ptype, pno, cphone, channel) {
            $("#CustNo").val(no);
            if (no) {
                $("#liCustNo").show();
            }
            $("#liPaperType").hide();
            $("#liPaperNo").hide();
            $("#CustName").val(name);
            $("#PaperType").val(ptype);
            $("#PaperNo").val(pno);
            $("#Phone").val(cphone);

            $("#CustName").attr("readOnly", "readOnly");
            $("#Phone").attr("readOnly", "readOnly");
            $('#btnPaper').hide();
            $('#btnclear').show();
            $('#ephone').parent().show();
        }
        
    </script>
}

